package com.zmn.plat.business.impl.extension.serv.category;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zmn.common.utils.date.DateUtil;
import com.zmn.common.utils.string.InitialUtil;
import com.zmn.plat.business.interfaces.extension.serv.category.ExtensionServCategoryBService;
import com.zmn.plat.model.entity.extension.serv.category.ExtensionServCategory;
import com.zmn.plat.services.interfaces.extension.serv.category.ExtensionServCategoryService;

/**
 * @author linfeng
 * @description 推广服务分类
 * @since 2019/12/24 14:30
 * @modifier
 **/
@Service
@SuppressWarnings("Duplicates")
public class ExtensionServCategoryBServiceImpl implements ExtensionServCategoryBService {
    @Autowired
    private ExtensionServCategoryService extensionServCategoryService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Integer addEdit(ExtensionServCategory extensionServCategory, String creater) {
        Date now = DateUtil.getNow();
        Integer categId = extensionServCategory.getCategId();
        String firstLetter = InitialUtil.getFristEnName(extensionServCategory.getName());
        extensionServCategory.setFirstLetter(firstLetter == null ? "" : firstLetter);
        if (categId == null || categId == 0) {
            extensionServCategory.setCreater(creater);
            extensionServCategory.setCreateTime(now);
            return extensionServCategoryService.insert(extensionServCategory);
        } else {
            extensionServCategory.setUpdater(creater);
            extensionServCategory.setUpdateTime(now);
            return extensionServCategoryService.updateByKey(extensionServCategory);
        }
    }
}
